<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div,p{
            width: 300px;
            height: 100px;
            line-height: 100px;
            color: #fff;
            background-color: pink;
        }
    </style>
</head>
<body>
    <button>显示当前系统时间</button>
    <div>装个时间</div>
    <p>123</p>
    <script>
        //当我们点击按钮 div里面的文字为发生变化
        var btn = document.querySelector('button');
        var div = document.querySelector('div');
        var date = new Date();

        // console.log(timer);
        btn.onclick = function () {
            div.innerText = getTime();

        }

        function getTime() {
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var dates = date.getDate();
            var arr = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六',]
            var day = date.getDay();
            return ('今天是:'+year+'年'+month+'月'+dates+'日'+arr[day]);
        }
        //元素可以不用添加事件
        var p = document.querySelector('p');
        p.innerHTML = getTime();
    </script>
</body>
</html>